/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.flexengine.map;

import com.flexengine.engine.Priority;
import com.flexengine.engine.Renderable;
import com.flexengine.engine.Updatable;
import com.flexengine.math.Point2D;
import com.flexengine.view.Graphics;
import com.flexengine.view.Texture;
import com.flexengine.xml.Attribute;
import com.flexengine.xml.Element;
import com.flexengine.xml.Root;

/**
 * @author Luann R. Athayde
 * @version 1.0
 * @since 1.0
 */
@Root
public class Tile implements Renderable, Updatable {
    
    public static final int TILE_WIDTH  = 40;
    public static final int TILE_HEIGHT = 40;
    
    @Attribute
    private String  name;
    @Attribute
    private boolean visible;
    private Point2D location;
    @Element
    private Texture texture;

    public Tile(String name, boolean visible, Texture texture) {
        this.name = name;
        this.visible = visible;
        this.location = new Point2D();
        this.texture = texture;
    }

    public Tile() {
        this("Tile", true, null);
    }
    
    @Override
    public void render(Graphics graphics) {
        if ( texture!=null ) {
            graphics.draw(texture, (int)location.getX(), (int)location.getY());
        }
        /*
        graphics.setColor(Color.WHITE);
        graphics.drawRect((int)location.getX(), (int)location.getY(), TILE_WIDTH, TILE_HEIGHT);
        */
    }

    @Override
    public void update(Long time, Long totalTime) {
        
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Point2D getLocation() {
        return location;
    }

    public void setLocation(Point2D location) {
        this.location = location;
    }
    
    public void setLocation(float x, float y) {
        this.location.setLocation(x, y);
    }

    @Override
    public Priority getPriority() {
        return Priority.NORMAL_PRIORITY;
    }

    @Override
    public boolean isVisible() {
        return visible;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    public void setTexture(Texture texture) {
        this.texture = texture;
    }

    public Texture getTexture() {
        return texture;
    }

    @Override
    public String toString() {
        return "Tile{" + "name=" + name + ", visible=" + visible + ", location=" + location + ", texture=" + texture + '}';
    }
    
}
